import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:interview/config/app_config.dart';
import 'package:interview/pages/account/login_page.dart';
import 'package:interview/pages/opt/opt_page.dart';
import 'package:interview/pages/question/question_page.dart';
import 'package:interview/pages/record/record_page.dart';
import 'package:interview/pages/search/search_page.dart';
import 'package:interview/pages/setting/setting_page.dart';
import 'package:interview/pages/start/start_page.dart';
import 'package:interview/pages/tabbar/tabbar.dart';
import 'package:interview/pages/task/task_page.dart';
import 'package:interview/pages/web/web_page.dart';
import 'package:interview/providers/theme_providers.dart';
import 'package:interview/theme/app_theme.dart';
import 'package:provider/provider.dart';

class MyApp extends StatelessWidget {
  final AppConfig config;

  const MyApp({super.key, required this.config});

  @override
  Widget build(BuildContext context) {
    // 通过 Provider 获取 ThemeProvider 并初始化
    final themeProvider = Provider.of<ThemeProvider>(context);
    
    return GetMaterialApp(
      title: config.appName,
      theme: AppThemes.lightTheme, // 亮色主题
      darkTheme: AppThemes.darkTheme, // 暗色主题
      themeMode: themeProvider.themeMode, // 动态主题
      initialRoute: config.initialRoute,
      getPages:[
        GetPage(
          name: '/start',
          page: () => const StartPage(),
          transition: Transition.cupertino, // 设置 Cupertino 风格过渡
          transitionDuration: Duration(milliseconds: 500), // 可以调整过渡动画的时长
        ),
        GetPage(
          name: '/home', 
          page: () => const Tabbar(),
          transition: Transition.cupertino, // 设置 Cupertino 风格过渡
          transitionDuration: Duration(milliseconds: 500), // 可以调整过渡动画的时长
        ),
        GetPage(
          name: '/login', 
          page: () => const LoginPage(),
          transition: Transition.cupertino, // 设置 Cupertino 风格过渡
          transitionDuration: Duration(milliseconds: 500), // 可以调整过渡动画的时长
        ),
        GetPage(
          name: '/webpage',
          page: () {
            final args = Get.arguments as Map<String, dynamic>;
            return WebPage(
              title: args['title'] ?? 'Web Page',
              url: args['url'] ?? '',
            );
          },
          transition: Transition.cupertino,
          transitionDuration: Duration(milliseconds: 500),
        ),
        GetPage(
          name: '/questionpage',
          page: () {
            final args = Get.arguments as Map<String, dynamic>;
            return QuestionPage(
              id:args['id'] ?? '',
              ids: List<String>.from(args["ids"]),
              typeId: args["typeId"] ?? 0,
              views:args["views"] ?? 0,
              tab:args["tab"] ?? '',
            );
          },
          transition: Transition.cupertino,
          transitionDuration: Duration(milliseconds: 500),
        ),
        GetPage(
          name: '/searchpage', 
          page: (){
            final args = Get.arguments as Map<String, dynamic>? ?? {};
            return SearchPage(
              tabKeyword: args['tabKeyword'], // 如果未传递，默认为 null
            );
          },
          transition: Transition.cupertino,
          transitionDuration: Duration(milliseconds: 500),
        ),
        GetPage(
          name: '/optpage', 
          page: () => OptPage(),
          transition: Transition.cupertino,
          transitionDuration: Duration(milliseconds: 500),
        ),
        GetPage(
          name: '/settingpage', 
          page: () => SettingPage(),
          transition: Transition.cupertino,
          transitionDuration: Duration(milliseconds: 500),
        ),
        GetPage(
          name: '/recordpage', 
          page: () => RecordPage(),
          transition: Transition.cupertino,
          transitionDuration: Duration(milliseconds: 500),
        ),
        GetPage(
          name: '/taskpage', 
          page: () => TaskPage(),
          transition: Transition.cupertino,
          transitionDuration: Duration(milliseconds: 500),
        ),
      ]
    );
  }
}

